import HttpUtils from "../../common/utils/HttpUtils";
import Urls from "../../common/utils/Urls";
import urlHook from "../../common/utils/urlHook";
import CommonUtils from "../../common/utils/CommonUtils";

export default class AnnoceComp extends React.Component {
    constructor() {
        super();
        this.state = {
            datalists: [
                "运费标准调整公告运费标公告运费标",
                "运费标准调整公告运费标",
                "运费标准调整公告运费标",
                "运费标准调整公告运费标",
                "运费标准调整公告运费标"
            ]
        };
    }

    componentDidMount() {
        this.onlineNotices();
    }

    onlineNotices() {
        const {number}=this.props
        const size =number?11: (global.hasLogin ? 5 : 11);
        HttpUtils.onlineNotices(size)
            .then(res => {
                console.log(res);
                this.setState({
                    datalists: res.entities
                });
            })
            .catch(err => {
                console.log(err);
            });
    }

    render() {
        const { datalists } = this.state;
        return (
            <div className={"annoce-comp-box"}>
                <div className={"annoce-comp-header"}>
                    <p className={"annoce-comp-title-left"}>通知公告</p>
                    <a
                        target={"_blank"}
                        href={urlHook.information}
                        className={"annoce-comp-title-right"}
                    >
                        查看更多 >
                    </a>
                </div>
                <div style={{ display: "block" }}>
                    {datalists &&
                        datalists.map((item, index) => {
                            let date = CommonUtils.getDateStr(item.publishTime);
                            return (
                                <div
                                    key={index}
                                    className={"annoce-comp-text-wrapper"}
                                >
                                    <a
                                        target={"_blank"}
                                        href={urlHook.infodetails(
                                            item.id,
                                            date
                                        )}
                                        className={"annoce-comp-text-content"}
                                    >
                                        <div
                                            className={"annoce-comp-text-dot"}
                                        />
                                        <p className={"annoce-comp-text-p"}>
                                            {item.title}
                                        </p>
                                    </a>
                                    {datalists &&
                                    datalists.length - 1 == index ? null : (
                                        <div
                                            className={
                                                "annoce-comp-text-bottom-line"
                                            }
                                        />
                                    )}
                                </div>
                            );
                        })}
                </div>
            </div>
        );
    }
}
